CC = javac
FLAGS = -g -target 1.5
RUN_FLAGS = -enableassertions
MAIN = FuzzyApplication
SRCS= $(wildcard *.java)
BIN=bin
OBJS= $(patsubst %.java,$(BIN)/%.class,$(SRCS))
JAR=pysydelet.jar
APPLETPAGE=myapplet.html
WEBBROWSER=firefox

# on my mac, I'd rather use open
ifeq ($(shell uname),Darwin)
    WEBBROWSER=open
endif

.PHONY:	default all rebuild run full dist clean

default: init full

all:	init $(OBJS)

# clean out crap and build all
rebuild:	clean init full

# build everything that's changed (faster than building each separately)
# requires make init, but I think that interferes with $?
full:	$(SRCS)
	$(CC) $(FLAGS) -d $(BIN) $?

# execute our application
run:    all
	cd $(BIN) && java $(RUN_FLAGS) $(MAIN)

# HACK: currently a hack to put the html in the bin directory.
# TODO: Can we make this use jars?
run-applet:    all
	ln -f $(APPLETPAGE) $(BIN)/. && $(WEBBROWSER) $(BIN)/$(APPLETPAGE) 

# create our jar
dist:	init full $(BIN)/Manifest.txt
	cd $(BIN) && jar cmf Manifest.txt ../$(JAR) *.class ; cd -

$(BIN)/Manifest.txt:
	echo "Main-Class: $(MAIN)" > $@

clean:
	-rm -rf $(JAR) $(BIN) tags

init:	$(BIN)


### Utilities

# make exuberant ctags file
tags:   $(SRCS)
	ctags $(SRCS) >$@


### Rules so make knows what to do

# java build rule
$(BIN)/%.class:	%.java
	$(CC) $(FLAGS) -d $(BIN) $?

# create the bin directory for our class files
$(BIN):	
	mkdir -p $(BIN)

